//
//  CommonUntils.m
//  BaishidaiKnight
//
//  Created by mac book on 2019/1/28.
//  Copyright © 2019年 sy. All rights reserved.
//

#import "CommonUntils.h"
#import <MapKit/MKMapItem.h>
#import <CoreLocation/CoreLocation.h>
#import "JZLocationConverter.h"//坐标转换


@implementation CommonUntils

#pragma mark - 创建button
+(UIButton *)createBtnFrame:(CGRect)frame
                      title:(NSString *)title
                 fontOfSize:(float)fontOfSize
              textAlignment:(NSTextAlignment)textAlignment
                 titleColor:(UIColor *)titleColor
            backgroundColor:(UIColor *)backgroundColor
{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    btn.frame = frame;
    
    btn.titleLabel.font = [UIFont systemFontOfSize:fontOfSize];
    
    btn.titleLabel.textAlignment = textAlignment;
    
    [btn setTitle:title forState:UIControlStateNormal];
    
    [btn setTitleColor:titleColor forState:UIControlStateNormal];
    
    [btn setBackgroundColor:backgroundColor];
    
    return btn;
    
}



#pragma mark - 创建label
+(UILabel *)createLabelFrame:(CGRect)frame
                        text:(NSString *)text
                   textColor:(UIColor *)textColor
                  fontOfSize:(UIFont *)fontOfSize
               textAlignment:(NSTextAlignment)textAlignment
               numberOfLines:(NSInteger)numberOfLines
               lineBreakMode:(NSLineBreakMode)lineBreakMode
{
    
    
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    
    label.text = text;
    
    label.font = fontOfSize;
    
    label.textAlignment = textAlignment;
    
    label.textColor = textColor;
    
    label.numberOfLines = numberOfLines;
    
    label.lineBreakMode = lineBreakMode;
    
    return label;
    
}

#pragma mark - 创建VerticalLabel
+(TTTAttributedLabel *)createVerticalLabelFrame:(CGRect)frame
                                      text:(NSString *)text
                                 textColor:(UIColor *)textColor
                                fontOfSize:(UIFont *)fontOfSize
                             textAlignment:(NSTextAlignment)textAlignment
                             numberOfLines:(NSInteger)numberOfLines
                             lineBreakMode:(NSLineBreakMode)lineBreakMode
{
    
    TTTAttributedLabel *label = [[TTTAttributedLabel alloc] initWithFrame:frame];
    
    label.verticalAlignment= TTTAttributedLabelVerticalAlignmentTop;

    label.text = text;
    
    label.font = fontOfSize;
    
    label.textAlignment = textAlignment;
    
    label.textColor = textColor;
    
    label.numberOfLines = numberOfLines;
    
    label.lineBreakMode = lineBreakMode;
    
    return label;
    
}

#pragma mark - 创建textField
+(UITextField *)createTextFieldFrame:(CGRect )frame
                         placeholder:(NSString *)placeholder
                         borderStyle:(UITextBorderStyle)borderStyle
                           textColor:(UIColor *)textColor
                          fontOfSize:(float)fontOfSize
                       textAlignment:(NSTextAlignment)textAlignment
{
    
    UITextField *textField = [[UITextField alloc] init];
    
    textField.frame = frame;
    
    textField.placeholder = placeholder;
    
    textField.borderStyle = borderStyle;
    
    textField.font = [UIFont systemFontOfSize:fontOfSize];
    
    textField.textAlignment = textAlignment;
    
    textField.textColor = textColor;
    
    return textField;
    
}

/**
 手机号码 13[0-9],14[5|7|9],15[0-3],15[5-9],17[0|1|3|5|6|7|8],18[0-9]
 移动：134[0-8],13[5-9],147,15[0-2],15[7-9],178,18[2-4],18[7-8]
 联通：13[0-2],145,15[5-6],17[5-6],18[5-6]
 电信：133,1349,149,153,173,177,180,181,189
 虚拟运营商: 170[0-2]电信  170[3|5|6]移动 170[4|7|8|9],171 联通
 上网卡又称数据卡，14号段为上网卡专属号段，中国联通上网卡号段为145，中国移动上网卡号段为147，中国电信上网卡号段为149
 */
+(BOOL)isMobilePhone:(NSString *)phoneNum
{
    NSString * MOBIL = @"^1(3[0-9]|4[579]|5[0-35-9]|7[01356]|8[0-9])\\d{8}$";
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBIL];
    if ([regextestmobile evaluateWithObject:phoneNum]) {
        return YES;
    }
    return NO;
}

//密码设置判断
+ (BOOL) validatePassword:(NSString *)passWord
{
    /**
     /^    匹配输入字符串的开始位置
     (
     [A-Za-z0-9]     大小写字母和数字任选
     {8,20}    长度大于8小于20
     )
     $/    匹配输入字符串的结束位置
     */
//    NSString *passWordRegex = @"^[A-Za-z0-9]{8,20}$";
//    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];
//    return [passWordPredicate evaluateWithObject:passWord];
    
    // 判断长度大于6位后再接着判断是否同时包含数字和大小写字母
    NSString * regex =@"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,20}$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    return [pred evaluateWithObject:passWord];
    
    
    
}


//身份证号判断
+ (BOOL)isValidCardNumber:(NSString *)value {
    value = [value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    long length = 0;
    
    if (!value) {
        return false;
    } else {
        length = value.length;
        if (length != 15 && length != 18) {
            return false;
        }
    }
    // 省份代码
    NSArray *areasArray =@[@"11",@"12", @"13",@"14", @"15",@"21", @"22",@"23", @"31",@"32", @"33",@"34", @"35",@"36", @"37",@"41", @"42",@"43", @"44",@"45", @"46",@"50", @"51",@"52", @"53",@"54", @"61",@"62", @"63",@"64", @"65",@"71", @"81",@"82", @"91"];
    
    NSString *valueStart2 = [value substringToIndex:2];
    BOOL areaFlag = FALSE;
    for (NSString *areaCode in areasArray) {
        if ([areaCode isEqualToString:valueStart2]) {
            areaFlag = YES;
            break;
        }
    }
    
    if (!areaFlag) {
        return false;
    }
    
    NSRegularExpression *regularExpression;
    NSUInteger numberofMatch;
    
    int year = 0;
    switch (length) {
        case 15:
            year = [value substringWithRange:NSMakeRange(6,2)].intValue + 1900;
            if (year % 4 == 0 || (year % 100 == 0 && year % 4 == 0)) {
                
                regularExpression = [[NSRegularExpression alloc] initWithPattern:@"^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$"
                                                                         options:NSRegularExpressionCaseInsensitive
                                                                           error:nil];//测试出生日期的合法性
            }else {
                regularExpression = [[NSRegularExpression alloc]initWithPattern:@"^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$"
                                                                        options:NSRegularExpressionCaseInsensitive
                                                                          error:nil];//测试出生日期的合法性
            }
            numberofMatch = [regularExpression numberOfMatchesInString:value
                                                               options:NSMatchingReportProgress
                                                                 range:NSMakeRange(0, value.length)];
            
            if(numberofMatch >0) {
                return YES;
            }else {
                return NO;
            }
        case 18:
            year = [value substringWithRange:NSMakeRange(6,4)].intValue;
            if (year %4 ==0 || (year %100 ==0 && year %4 ==0)) {
                regularExpression = [[NSRegularExpression alloc]initWithPattern:@"^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$"
                                                                        options:NSRegularExpressionCaseInsensitive
                                                                          error:nil];//测试出生日期的合法性
            }else {
                regularExpression = [[NSRegularExpression alloc]initWithPattern:@"^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$"
                                                                        options:NSRegularExpressionCaseInsensitive
                                                                          error:nil];//测试出生日期的合法性
            }
            numberofMatch = [regularExpression numberOfMatchesInString:value
                                                               options:NSMatchingReportProgress
                                                                 range:NSMakeRange(0, value.length)];
            
            if(numberofMatch > 0) {
                int S = ([value substringWithRange:NSMakeRange(0,1)].intValue + [value substringWithRange:NSMakeRange(10,1)].intValue) *7 + ([value substringWithRange:NSMakeRange(1,1)].intValue + [value substringWithRange:NSMakeRange(11,1)].intValue) *9 + ([value substringWithRange:NSMakeRange(2,1)].intValue + [value substringWithRange:NSMakeRange(12,1)].intValue) *10 + ([value substringWithRange:NSMakeRange(3,1)].intValue + [value substringWithRange:NSMakeRange(13,1)].intValue) *5 + ([value substringWithRange:NSMakeRange(4,1)].intValue + [value substringWithRange:NSMakeRange(14,1)].intValue) *8 + ([value substringWithRange:NSMakeRange(5,1)].intValue + [value substringWithRange:NSMakeRange(15,1)].intValue) *4 + ([value substringWithRange:NSMakeRange(6,1)].intValue + [value substringWithRange:NSMakeRange(16,1)].intValue) *2 + [value substringWithRange:NSMakeRange(7,1)].intValue *1 + [value substringWithRange:NSMakeRange(8,1)].intValue *6 + [value substringWithRange:NSMakeRange(9,1)].intValue *3;
                int Y = S %11;
                NSString *M = @"F";
                NSString *JYM = @"10X98765432";
                M = [JYM substringWithRange:NSMakeRange(Y,1)];// 判断校验位
                if ([M isEqualToString:[value substringWithRange:NSMakeRange(17,1)]]) {
                    return YES;// 检测ID的校验位
                }else {
                    return NO;
                }
            }else {
                return NO;
            }
        default:
            return false;
    }
}


//车牌号格式校验(粤A8888澳)，18-05-21，增加新能源车牌校验
+(BOOL)checkCarID:(NSString *)carID
{
    if (carID.length==7) {
        //普通汽车，7位字符，不包含I和O，避免与数字1和0混淆
        NSString *carRegex = @"^[\u4e00-\u9fa5]{1}[a-hj-np-zA-HJ-NP-Z]{1}[a-hj-np-zA-HJ-NP-Z0-9]{4}[a-hj-np-zA-HJ-NP-Z0-9\u4e00-\u9fa5]$";
        NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];
        return [carTest evaluateWithObject:carID];
    }else if(carID.length==8){
        //新能源车,8位字符，第一位：省份简称（1位汉字），第二位：发牌机关代号（1位字母）;
        //小型车，第三位：只能用字母D或字母F，第四位：字母或者数字，后四位：必须使用数字;([DF][A-HJ-NP-Z0-9][0-9]{4})
        //大型车3-7位：必须使用数字，后一位：只能用字母D或字母F。([0-9]{5}[DF])
        NSString *carRegex = @"^[\u4e00-\u9fa5]{1}[a-hj-np-zA-HJ-NP-Z]{1}([0-9]{5}[d|f|D|F]|[d|f|D|F][a-hj-np-zA-HJ-NP-Z0-9][0-9]{4})$";
        NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];
        return [carTest evaluateWithObject:carID];
    }
    return NO;
}

//判断字符串是否全为[(数字)OR(数字|字母)OR(字母)OR(汉字)]

+(BOOL)isAllNumber:(NSString *)string
{
    NSString *condition = @"^[0-9]*$";//是否都是数字
    //    NSString *condition = @"^[A-Za-z]+$";//是否都是字母
    //    NSString *condition = @"^[A-Za-z0-9]+$";//是否都是字母和数字{6,16}
    //    NSString *condition = @"^[A-Za-z0-9]{6,16}$";//是否都是字母和数字且长度在[6,16]
    //    NSString *condition = @"^[\u4e00-\u9fa5]{0,}$";//只能输入汉字
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES%@",condition];
    return [predicate evaluateWithObject:string];
}



#pragma mark - 计算高度
+(CGFloat)getHeightFromString:(NSString *)string WithFont:(UIFont *)font AndWidth:(CGFloat)width{
    
    CGFloat contentH = [string boundingRectWithSize:CGSizeMake(width, MAXFLOAT)options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : font}context:nil].size.height;
    
    return contentH;
}

+(CGFloat)getHeightFromString:(NSString *)string WithBoldFont:(CGFloat)boldfont AndWidth:(CGFloat)width{
    
    CGFloat contentH = [string boundingRectWithSize:CGSizeMake(width, MAXFLOAT)options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:boldfont]}context:nil].size.height;
    
    return contentH;
}

#pragma mark - 计算宽度
+(CGFloat)getWidthFromString:(NSString *)string WithFont:(CGFloat)font AndHeight:(CGFloat)height{
    
    CGFloat contentH = [string boundingRectWithSize:CGSizeMake(MAXFLOAT, height)options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:font]}context:nil].size.width;
    
    return contentH;
}

#pragma mark - 计算label文本高度
+(CGFloat)textHeight:(NSString*)text withFontSize:(CGFloat)fontSize withWidth:(CGFloat)width{
    UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, MAXFLOAT)];
    label.font = [UIFont systemFontOfSize:fontSize];
    label.lineBreakMode = NSLineBreakByCharWrapping;
    label.text = text;
    label.numberOfLines = 0;
    [label sizeToFit];
    return label.frame.size.height;
}

+(NSMutableAttributedString *)changeLabelTextStyle:(NSString*)text  withChangeText:(NSString *)changeText withtextFont:(UIFont *)changeFont withtextColor:(UIColor *)changeColor{

    
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:text];
    [AttributedStr addAttribute:NSFontAttributeName value:changeFont range:[text rangeOfString:changeText]];
    [AttributedStr addAttribute:NSForegroundColorAttributeName value:changeColor range:[text rangeOfString:changeText]];
    
    return AttributedStr;
    
}

+(NSMutableAttributedString *)changeLabelTextStyle:(NSString*)text  withChangeText:(NSString *)changeText withtextFont:(CGFloat)changeFont withtextColor:(UIColor *)changeColor withChangeTextTwo:(NSString *)changeTextTwo withtextTwoFont:(CGFloat)changeTwoFont withtextTwoColor:(UIColor *)changeTwoColor {
    
    
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:text];
    [AttributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:changeFont] range:[text rangeOfString:changeText]];
    [AttributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:changeTwoFont] range:[text rangeOfString:changeTextTwo]];

    [AttributedStr addAttribute:NSForegroundColorAttributeName value:changeColor range:[text rangeOfString:changeText]];
    [AttributedStr addAttribute:NSForegroundColorAttributeName value:changeTwoColor range:[text rangeOfString:changeTextTwo]];

    return AttributedStr;
    
}




//获取当前时间
+ (NSString *)currentDateStr{
    NSDate *currentDate = [NSDate date];//获取当前时间，日期
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];// 创建一个时间格式化对象
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//设定时间格式,这里可以设置成自己需要的格式
    NSString *dateString = [dateFormatter stringFromDate:currentDate];//将时间转化成字符串
    return dateString;
}

//获取当前时间戳
+ (NSString *)currentTimeStr{
    NSDate* date = [NSDate dateWithTimeIntervalSinceNow:0];//获取当前时间0秒后的时间
    NSTimeInterval time=[date timeIntervalSince1970]*1000;// *1000 是精确到毫秒，不乘就是精确到秒
    NSString *timeString = [NSString stringWithFormat:@"%.0f", time];
    return timeString;
}
// 时间戳转时间,时间戳为13位是精确到毫秒的，10位精确到秒
+ (NSString *)getDateStringWithTimeStr:(NSString *)str{
    
    double time = [str doubleValue];
    NSDate *detailDate = [NSDate dateWithTimeIntervalSince1970:time];
    
//    NSTimeInterval time=[str doubleValue]/100;//传入的时间戳str如果是精确到毫秒的记得要/1000
//    NSDate *detailDate=[NSDate dateWithTimeIntervalSince1970:time];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; //实例化一个NSDateFormatter对象
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//@"yyyy-MM-dd HH:mm:ss SS"
    NSString *currentDateStr = [dateFormatter stringFromDate: detailDate];
    return currentDateStr;
}


//字符串转时间戳 如：2017-4-10 17:15:10
+ (NSString *)getTimeStrWithString:(NSString *)str{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];// 创建一个时间格式化对象
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; //设定时间的格式
    NSDate *tempDate = [dateFormatter dateFromString:str];//将字符串转换为时间对象
    NSString *timeStr = [NSString stringWithFormat:@"%ld", (long)[tempDate timeIntervalSince1970]*1000];//字符串转成时间戳,精确到毫秒*1000
    return timeStr;
}

//比较两个日期大小
+(int)compareDate:(NSString*)startDate withDate:(NSString*)endDate{
    
    int comparisonResult;
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *date1 = [[NSDate alloc] init];
    NSDate *date2 = [[NSDate alloc] init];
    date1 = [formatter dateFromString:startDate];
    date2 = [formatter dateFromString:endDate];
    NSComparisonResult result = [date1 compare:date2];
    switch (result)
    {
            //date02比date01大
        case NSOrderedAscending:
            comparisonResult = 1;
            break;
            //date02比date01小
        case NSOrderedDescending:
            comparisonResult = -1;
            break;
            //date02=date01
        case NSOrderedSame:
            comparisonResult = 0;
            break;
        default:
            NSLog(@"erorr dates %@, %@", date1, date2);
            break;
    }
    NSLog(@"comparisonResult==%ld",(long)comparisonResult);

    return comparisonResult;
}


+(NSString *)dateFromNowDate:(NSString *)orderdate{
    
    // 获取当前时时间戳 1466386762.345715 十位整数 6位小数
    NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970];
    // 创建时间戳(后台返回的时间 一般是13位数字)/1000
    NSTimeInterval createTime = [orderdate longLongValue];
    // 时间差
    NSTimeInterval time = createTime - currentTime ;
//    NSTimeInterval all = 15*60 -time;
    
    NSString *timeString = [NSString stringWithFormat:@"%.0f", time]; //转为字符型
    return timeString;
    
}
+(NSString *)dateFromOutDate:(NSString *)orderdate{
    
    // 获取当前时时间戳 1466386762.345715 十位整数 6位小数
    NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970];
    // 创建时间戳(后台返回的时间 一般是13位数字)/1000
    NSTimeInterval createTime = [orderdate longLongValue];
    // 时间差
    NSTimeInterval time = currentTime - createTime  ;
    //    NSTimeInterval all = 15*60 -time;
    
    NSString *timeString = [NSString stringWithFormat:@"%.0f", time]; //转为字符型
    return timeString;
    
}

//图片转字符串
+(NSString *)UIImageToBase64Str:(UIImage *) image
{
    NSData *data = UIImageJPEGRepresentation(image, 1.0f);
    NSString *encodedImageStr = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    return encodedImageStr;
}



//字符串转图片
+(UIImage *)Base64StrToUIImage:(NSString *)_encodedImageStr
{
    NSData *_decodedImageData   = [[NSData alloc] initWithBase64EncodedString:_encodedImageStr options:NSDataBase64DecodingIgnoreUnknownCharacters];
    UIImage *_decodedImage      = [UIImage imageWithData:_decodedImageData];
    return _decodedImage;
}


+(NSString *)cutOutTime:(NSString *)time{
    
    
    
    NSString *dateString = [NSString string] ;
    NSScanner *scanner = [NSScanner scannerWithString:time];
    [scanner scanUpToString:@" " intoString:&dateString];
    return dateString;
    
}

/**
 *  压缩图片到指定文件大小
 *
 *  @param image 目标图片
 *  @param size  目标大小（最大值）
 *
 *  @return 返回的图片文件
 */
+ (NSData *)compressOriginalImage:(UIImage *)image toMaxDataSizeKBytes:(CGFloat)size{
    
    NSData * data = UIImageJPEGRepresentation(image, 1.0);
    CGFloat dataKBytes = data.length/1000.0;
    CGFloat maxQuality = 0.9f;
    CGFloat lastData = dataKBytes;
    
    while (dataKBytes > size && maxQuality > 0.01f) {
        maxQuality = maxQuality - 0.01f;
        data = UIImageJPEGRepresentation(image, maxQuality);
        dataKBytes = data.length / 1000.0;
        if (lastData == dataKBytes) {
            break;
        }else{
            lastData = dataKBytes;
        }
    }
    return data;
}


+ (void)setBorderWithView:(UIView *)view top:(BOOL)top left:(BOOL)left bottom:(BOOL)bottom right:(BOOL)right borderColor:(UIColor *)color borderWidth:(CGFloat)width
{
    [view layoutIfNeeded];
    if (top) {
        CALayer *layer = [CALayer layer];
        layer.frame = CGRectMake(0, 0, view.frame.size.width, width);
        layer.backgroundColor = color.CGColor;
        [view.layer addSublayer:layer];
    }
    if (left) {
        CALayer *layer = [CALayer layer];
        layer.frame = CGRectMake(0, 0, width, view.frame.size.height);
        layer.backgroundColor = color.CGColor;
        [view.layer addSublayer:layer];
    }
    if (bottom) {
        CALayer *layer = [CALayer layer];
        layer.frame = CGRectMake(0, view.frame.size.height - width, view.frame.size.width, width);
        layer.backgroundColor = color.CGColor;
        [view.layer addSublayer:layer];
    }
    if (right) {
        CALayer *layer = [CALayer layer];
        layer.frame = CGRectMake(view.frame.size.width - width, 0, width, view.frame.size.height);
        layer.backgroundColor = color.CGColor;
        [view.layer addSublayer:layer];
    }
}

+ (void)setBorderWithLabel:(UILabel *)label top:(BOOL)top left:(BOOL)left bottom:(BOOL)bottom right:(BOOL)right borderColor:(UIColor *)color borderWidth:(CGFloat)width
{
    [label layoutIfNeeded];
    if (top) {
        CALayer *layer = [CALayer layer];
        layer.frame = CGRectMake(0, 0, label.frame.size.width, width);
        layer.backgroundColor = color.CGColor;
        [label.layer addSublayer:layer];
    }
    if (left) {
        CALayer *layer = [CALayer layer];
        layer.frame = CGRectMake(0, 0, width, label.frame.size.height);
        layer.backgroundColor = color.CGColor;
        [label.layer addSublayer:layer];
    }
    if (bottom) {
        CALayer *layer = [CALayer layer];
        layer.frame = CGRectMake(0, label.frame.size.height - width, label.frame.size.width, width);
        layer.backgroundColor = color.CGColor;
        [label.layer addSublayer:layer];
    }
    if (right) {
        CALayer *layer = [CALayer layer];
        layer.frame = CGRectMake(label.frame.size.width - width, 0, width, label.frame.size.height);
        layer.backgroundColor = color.CGColor;
        [label.layer addSublayer:layer];
    }
}

+ (NSInteger)getDifferenceByDate:(NSString *)date {
    
    
    //获得当前时间
    NSDate *now = [NSDate date];
    //实例化一个NSDateFormatter对象
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *oldDate = [dateFormatter dateFromString:date];
    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    unsigned int unitFlags = NSCalendarUnitDay;
    NSDateComponents *comps = [gregorian components:unitFlags fromDate:now  toDate:oldDate  options:0];
    if (comps < 0) {
        return 0;
    }
    return [comps day];
}

+ (BOOL)isBlankDictionary:(NSDictionary *)dic {
    
    if (!dic) {
        
        return YES;
        
    }
    
    if ([dic isKindOfClass:[NSNull class]]) {
        
        return YES;
        
    }
    
    if (!dic.count) {
        
        return YES;
        
    }
    
    if (dic == nil) {
        
        return YES;
        
    }
    
    if (dic == NULL) {
        
        return YES;
        
    }
    
    if (![dic isKindOfClass:[NSDictionary class]]) {
        
        return YES;
        
    }
    
    return NO;
    
}


/*   参数介绍
 
 lineSpacing (行间距)
 
 FirstLineHeadIndent(首行缩进字符个数)
 
 FontOfSize (字号)
 
 TextColor(字体颜色)
 
 text(字符串内容)
 
 AddLabel(在哪个LB上面使用该特性)
 
 */
+(void)settingLabelTextAttributesWithLineSpacing:(CGFloat)lineSpacing FirstLineHeadIndent:(CGFloat)firstLineHeadIndent FontOfSize:(CGFloat)fontOfSize Font:(UIFont *)font TextColor:(UIColor *)textColor text:(NSString *)text AddLabel:(UILabel *)label{
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    
    //行间距
    
    paragraphStyle.lineSpacing = lineSpacing;
    
    //首行缩进 (缩进个数 * 字号)
    
    paragraphStyle.firstLineHeadIndent = firstLineHeadIndent * fontOfSize;
    
    NSDictionary *attributeDic = @{
                                   
                                   NSFontAttributeName : font,
                                   
                                   NSParagraphStyleAttributeName : paragraphStyle,
                                   
                                   NSForegroundColorAttributeName : textColor
                                   
                                   };
    
    label.attributedText = [[NSAttributedString alloc] initWithString:text attributes:attributeDic];
    
}


+ (UIViewController *)getCurrentVC {
    UIViewController *result = nil;
    UIWindow * window = [[UIApplication sharedApplication] keyWindow];
    if (window.windowLevel != UIWindowLevelNormal) {
        NSArray *windows = [[UIApplication sharedApplication] windows];
        for(UIWindow * tmpWin in windows) {
            if (tmpWin.windowLevel == UIWindowLevelNormal) {
                window = tmpWin;
                break;
            }
        }
    }
    UIView *frontView = [[window subviews] objectAtIndex:0];
    id nextResponder = [frontView nextResponder];
    if ([nextResponder isKindOfClass:[UIViewController class]]) {
        result = nextResponder;
    } else {
        result = window.rootViewController;
    }
    return result;
}

+ (void)naviAddressWithDestination:(NSString *)destination  withLatitude:(NSString *)latitude withLongitude:(NSString *)longitude withController:(UIViewController *)vc{
    
    NSString *urlScheme = @"佰食袋骑士://";
    NSString *appName = @"佰食袋骑士";
    
    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([latitude doubleValue], [longitude doubleValue]);//要导航的终点的经纬度
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"选择地图" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    //这个判断其实是不需要的
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"http://maps.apple.com/"]]) {
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"苹果地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            
            CLLocationCoordinate2D desCoordinate = coordinate;
            
            MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
            MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:desCoordinate addressDictionary:nil]];
            toLocation.name = destination;//可传入目标地点名称
            [MKMapItem openMapsWithItems:@[currentLocation, toLocation]
                           launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];
        }];
        
        [alert addAction:action];
    }
    
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) {
        
        CLLocationCoordinate2D desCoordinate = [JZLocationConverter gcj02ToBd09:coordinate];//火星坐标转化为百度坐标
        
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"百度地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            
            //我的位置代表起点位置为当前位置，也可以输入其他位置作为起点位置，如天安门
            NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name:%@&mode=driving&coord_type=gcj02",desCoordinate.latitude, desCoordinate.longitude,destination] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            
            
            NSLog(@"%@",urlString);
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
            
        }];
        
        [alert addAction:action];
    }
    
    
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) {
        
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"高德地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            
            NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&lat=%f&lon=%f&dname=%@&dev=0&style=2",appName,urlScheme,coordinate.latitude, coordinate.longitude ,destination] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            
            NSLog(@"%@",urlString);
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
            
        }];
        
        [alert addAction:action];
    }
    
    
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) {
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"谷歌地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            
            CLLocationCoordinate2D desCoordinate = coordinate;
            
            NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",appName,urlScheme,desCoordinate.latitude, desCoordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            
            NSLog(@"%@",urlString);
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
            
        }];
        
        [alert addAction:action];
    }
    
    
    if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"qqmap://"]])    {
        
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"腾讯地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            
            CLLocationCoordinate2D desCoordinate = coordinate;
            
            NSString *urlString = [[NSString stringWithFormat:@"qqmap://map/routeplan?type=drive&from=我的位置&to=%@&tocoord=%f,%f&policy=1&referer=%@", destination, desCoordinate.latitude, desCoordinate.longitude, appName] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            
            NSLog(@"%@",urlString);
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
            
        }];
        
        [alert addAction:action];
    }
    
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alert addAction:action];
    
    [vc presentViewController:alert animated:YES completion:^{
        
    }];
}


+(NSString *)convertToStringWithDate:(NSDate *)date{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *destDateString = [dateFormatter stringFromDate:date];
    return destDateString;
}

+(NSString *)convertToStringWithDate:(NSDate *)date format:(NSString *)format{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:format];
    NSString *destDateString = [dateFormatter stringFromDate:date];
    return destDateString;
}
+(NSString *)currentDate{
    NSDate *today=[NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *destDateString = [dateFormatter stringFromDate:today];
    return destDateString;
}

+(NSString *)currentDateWithFormat:(NSString *)format{
    NSDate *today=[NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:format];
    NSString *destDateString = [dateFormatter stringFromDate:today];
    return destDateString;
}
+(NSDate *)convertToDateWithStr:(NSString *)dateStr{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *date=[formatter dateFromString:dateStr];
    return date;
}
+ (NSDate*) convertToDateWithStr:(NSString*)dateStr format:(NSString*)format{
    if(!format)
        [self convertToDateWithStr:dateStr];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    [formatter setDateFormat:format];
    NSDate *date=[formatter dateFromString:dateStr];
    return date;
}

+(NSString *)convertToChineseFormat:(NSString *)dateStr
{
    NSDate *timedate=[self convertToDateWithStr:dateStr];
    
    NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
    [dateFormatter1 setDateFormat:@"HH:mm"];
    NSString *showtimeString = [dateFormatter1 stringFromDate:timedate];
    NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];
    [dateFormatter2 setDateFormat:@"yyyy-MM-dd"];
    NSString *showDateString=[dateFormatter2 stringFromDate:timedate];
    NSTimeInterval timeValue = [timedate timeIntervalSince1970];
    NSDate *today=[NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *destDateString = [dateFormatter stringFromDate:today];
    destDateString=[destDateString stringByAppendingString:@" 00:00"];
    NSDate *todayDate=[self convertToDateWithStr:destDateString];
    NSTimeInterval todayDateValue = [todayDate timeIntervalSince1970];
    
    NSTimeInterval secondsPerDay = 24 * 60 * 60;
    NSDate *earlyDate=[todayDate dateByAddingTimeInterval:-secondsPerDay];
    NSTimeInterval earlyDateValue = [earlyDate timeIntervalSince1970];
    if((long long int)todayDateValue < (long long int)timeValue)
    {
        showtimeString=[NSString stringWithFormat:@"今天 %@",showtimeString];
    }
    
    else if((long long int)earlyDateValue < (long long int)timeValue && (long long int)todayDateValue > (long long int)timeValue )
    {
        showtimeString=[NSString stringWithFormat:@"昨天 %@",showtimeString];
    }
    else{
        showtimeString=[NSString stringWithFormat:@"%@",showDateString];
    }
    return showtimeString;
}

+(NSString*)weekDays:(NSString *)dateStr
{
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDate *dates=[self convertToDateWithStr:dateStr];
    NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit |
    NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    NSDateComponents *comps  = [calendar components:unitFlags fromDate:dates];
    NSInteger  week = [comps weekday];
    switch (week) {
        case 1:
            return @"星期日";
            break;
        case 2:
            return @"星期一";
            break;
        case 3:
            return @"星期二";
            break;
        case 4:
            return @"星期三";
            break;
        case 5:
            return @"星期四";
            break;
        case 6:
            return @"星期五";
            break;
        default:
            return @"星期六";
            break;
    }
}

+(NSString *)timeStampConvertToDateString:(NSString *)timeStamp{
    double lastactivityInterval = [timeStamp doubleValue];
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    formatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSDate* date = [NSDate dateWithTimeIntervalSince1970:lastactivityInterval];
    NSString* dateString = [formatter stringFromDate:date];
    return dateString;
}
+(NSString *)timeStampConvertToDateString:(NSString *)timeStamp formate:(NSString *)formate{
    if(!formate)
        [self timeStampConvertToDateString:timeStamp];
    double lastactivityInterval = [timeStamp doubleValue];
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    formatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:formate];
    NSDate* date = [NSDate dateWithTimeIntervalSince1970:lastactivityInterval];
    NSString* dateString = [formatter stringFromDate:date];
    return dateString;
}
+(BOOL)isValidateEmail:(NSString *)email
{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:email];
}

+(BOOL) isValidateMobile:(NSString *)mobile
{
    NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(17[0-9])|(18[0,0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
}
+ (BOOL) isEmptyOrNULLOrnil:(NSString *)string {
    if ([CommonUntils isNULLOrnil:string]) {
        return YES;
    }
    if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
        return YES;
    }
    return NO;
}
+ (BOOL)stingContainsString:(NSString *)string withString:(NSString*)containsString
{
    BOOL ret = YES;
    do {
        NSRange range = [string rangeOfString:containsString];
        if (range.location ==NSNotFound)
        {
            ret = NO;
        }
    } while (0);
    return ret;
}

+(Boolean)isNULLOrnil:(id)sender{
    if (((NSNull *)sender == [NSNull null])||(sender==nil))
        return YES;
    return NO;
}

+(NSString *)integerConvertToString:(NSInteger)num{
    return [NSString stringWithFormat:@"%ld",(long)num];
}

+(NSString *)intConvertToString:(int)num{
    return [NSString stringWithFormat:@"%d",num];
}

+ (float)calculateTextHeight:(NSString*)str font:(UIFont *)font width:(float)width{
    CGSize constraint = CGSizeMake(width, CGFLOAT_MAX);
    NSDictionary * attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
    NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:str attributes:attributes];
    CGRect rect = [attributedText boundingRectWithSize:constraint options:NSStringDrawingUsesLineFragmentOrigin context:nil];
    CGSize size = rect.size;
    return size.height;
}
+(float)calculateAttributeStrHeight:(NSAttributedString*)str width:(float)width{
    int total_height = 0;
    
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)str);
    CGRect drawingRect = CGRectMake(0, 0, width, 1000);
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddRect(path, NULL, drawingRect);
    CTFrameRef textFrame = CTFramesetterCreateFrame(framesetter,CFRangeMake(0,0), path, NULL);
    CGPathRelease(path);
    CFRelease(framesetter);
    
    NSArray *linesArray = (NSArray *) CTFrameGetLines(textFrame);
    
    CGPoint origins[[linesArray count]];
    CTFrameGetLineOrigins(textFrame, CFRangeMake(0, 0), origins);
    
    int line_y = (int) origins[[linesArray count] -1].y;  //最后一行line的原点y坐标
    
    CGFloat ascent;
    CGFloat descent;
    CGFloat leading;
    
    CTLineRef line = (__bridge CTLineRef) [linesArray objectAtIndex:[linesArray count]-1];
    CTLineGetTypographicBounds(line, &ascent, &descent, &leading);
    
    total_height = 1000 - line_y + (int) descent +1;    //+1为了纠正descent转换成int小数点后舍去的值
    
    CFRelease(textFrame);
    
    return total_height;
}
+(float)calculateAttributeStrHeight:(NSAttributedString *)str font:(UIFont *)font width:(float)width
{
    float total_height = 0.f;
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)str);
    CGRect drawingRect = CGRectMake(0, 0, width, 1000);
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddRect(path, NULL, drawingRect);
    CTFrameRef textFrame = CTFramesetterCreateFrame(framesetter,CFRangeMake(0,0), path, NULL);
    CGPathRelease(path);
    CFRelease(framesetter);
    NSArray *linesArray = (NSArray *) CTFrameGetLines(textFrame);
    CGPoint origins[[linesArray count]];
    CTFrameGetLineOrigins(textFrame, CFRangeMake(0, 0), origins);
    float line_y = (int) origins[[linesArray count] -1].y;
    CGFloat ascent;
    CGFloat descent;
    CGFloat leading;
    CTLineRef line = (__bridge CTLineRef) [linesArray objectAtIndex:[linesArray count]-1];
    CTLineGetTypographicBounds(line, &ascent, &descent, &leading);
    total_height = 1000 - line_y + (int) descent;
    CFRelease(textFrame);
    return total_height;
    
}

+ (float)calculateTextWidth:(NSString*)str font:(UIFont *)font  height:(float)height{
    CGSize constraint = CGSizeMake(CGFLOAT_MAX, height);
    NSDictionary * attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
    NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:str   attributes:attributes];
    CGRect rect = [attributedText boundingRectWithSize:constraint  options:NSStringDrawingUsesLineFragmentOrigin  context:nil];
    CGSize size = rect.size;
    return size.width;
}

+ (float)calculateTextWidth:(NSString*)str font:(UIFont *)font{
    CGSize size =[str sizeWithAttributes:@{NSFontAttributeName:font}];
    return size.width;
}


+(NSString *)calculateContent:(NSString *)str width:(CGFloat)width{
    NSUInteger length = [str length];
    NSRange range = NSMakeRange(0, length);
    NSString* empty =nil;
    while(range.location != NSNotFound)
    {
        //获取特定字符位置
        range = [str rangeOfString: @"w='288' h='" options:0 range:range];
        
        if(range.location != NSNotFound)
        {
            //从自定位置开始截取字符
            empty = [str substringWithRange:NSMakeRange(range.location+range.length,str.length-(range.location+range.length))];
            
            // range = NSMakeRange(range.location + range.length, length - (range.location + range.length));
            //找到下一个特定字符
            NSRange  emptyRange = [empty rangeOfString: @"'"];
            
            //  NSLog(@"%@",NSStringFromRange(emptyRange));
            //找到高度字符串
            NSString* newStr = [empty substringWithRange:NSMakeRange(0, emptyRange.location)];
            CGFloat width = 288.f;
            CGFloat height = [newStr floatValue];
            // NSLog(@"%@",newStr);
            
            CGFloat newWidth = width;
            CGFloat newHeight = height*newWidth/width;
            //创建替换字符的位置
            NSRange subRang = NSMakeRange(range.location, range.length+emptyRange.location+1);
            //创建替换字符
            NSString* subStr =[NSString stringWithFormat:@"width ='%.2f' height='%.2f'",newWidth,newHeight];
            //替换字符 返回新字符串
            str = [str stringByReplacingCharactersInRange:subRang withString:subStr];
            
            length  =str.length;
            range = NSMakeRange(0, length);
            
        }
    }
    return str;
}
+ (NSString*)getTheCorrectNum:(NSString*)tempString
{
    //计算截取的长度
    NSUInteger endLength = tempString.length;
    //判断字符串是否包含 .
    if ([tempString containsString:@"."]) {
        //取得 . 的位置
        NSRange pointRange = [tempString rangeOfString:@"."];
        NSLog(@"%lu",pointRange.location);
        //判断 . 后面有几位
        NSUInteger f = tempString.length - 1 - pointRange.location;
        //如果大于2位就截取字符串保留两位,如果小于两位,直接截取
        if (f > 2) {
            endLength = pointRange.location + 2;
        }
    }
    //先将tempString转换成char型数组
    NSUInteger start = 0;
    const char *tempChar = [tempString UTF8String];
    //遍历,去除取得第一位不是0的位置
    for (int i = 0; i < tempString.length; i++) {
        if (tempChar[i] == '0') {
            start++;
        }else {
            break;
        }
    }
    //根据最终的开始位置,计算长度,并截取
    NSRange range = {start,endLength-start};
    tempString = [tempString substringWithRange:range];
    return tempString;
}

@end
